package com.cly.controller;

import com.cly.base.controller.BaseController;
import com.cly.dto.PostDto;
import com.cly.entity.Post;
import com.cly.result.JsonRequest;
import com.cly.service.IPostService;
import com.cly.vo.PostVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位控制类
 *
 * @author by 春风能解释
 * <p>
 * 2024/11/13
 */
@RestController
@RequestMapping("/post")
@Tag(name = "岗位控制类", description = "岗位操作访问接口")
public class PostController extends BaseController<IPostService, Post> {

    /**
     * 分页查询岗位
     *
     * @param current 页码
     * @param size    页长
     * @param post    查询条件
     * @return JSON
     */
    @PostMapping("/page")
    @Operation(summary = "分页查询岗位")
    public JsonRequest<List<PostVo>> lookPostList(
            @Parameter(description = "页码", required = true)
            @RequestParam Integer current,
            @Parameter(description = "页长", required = true)
            @RequestParam Integer size,
            @Parameter(description = "条件")
            @RequestBody PostDto post) {
        return baseService.lookPostList(current, size, post);
    }

    /**
     * 新增岗位
     *
     * @param post 新增数据
     * @return JSON
     */
    @PostMapping
    @Operation(summary = "新增岗位")
    public JsonRequest<Boolean> addOnePost(
            @Parameter(description = "岗位", required = true)
            @RequestBody Post post) {
        return baseService.addOnePost(post);
    }

    /**
     * 修改岗位
     *
     * @param post 修改数据
     * @return JSON
     */
    @PutMapping
    @Operation(summary = "修改岗位")
    public JsonRequest<Boolean> updateOnePost(
            @Parameter(description = "岗位", required = true)
            @RequestBody Post post) {
        return baseService.updateOnePost(post);
    }

    /**
     * 删除岗位
     *
     * @param ids 岗位id
     * @return JSON
     */
    @DeleteMapping
    @Operation(summary = "删除岗位")
    public JsonRequest<Boolean> deletePost(
            @Parameter(description = "岗位ID", required = true)
            @RequestBody List<Long> ids) {
        return baseService.deletePost(ids);
    }
}
